﻿using HML.Design;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;

namespace HML
{
    /// <summary>
    /// DropDownListPlus下拉列表弹层
    /// </summary>
    [TypeConverter(typeof(PropertyOrderConverter))]
    public class DropDownListPlusListItemsStyle
    {
        #region 属性

        private int roundSize = 6;
        /// <summary>
        /// 圆角Size
        /// </summary>
        [Description("圆角Size")]
        [PropertyOrder(-200)]
        [DefaultValue(6)]
        public int RoundSize
        {
            get { return this.roundSize; }
            set
            {
                if (value < 1)
                    value = 1;
                if (this.roundSize == value)
                    return;

                this.roundSize = value;
            }
        }

        private Color borderColor = Color.FromArgb(199, 199, 199);
        /// <summary>
        /// 边框颜色
        /// </summary>
        [Description("边框颜色")]
        [PropertyOrder(-199)]
        [DefaultValue(typeof(Color), "199, 199, 199")]
        public Color BorderColor
        {
            get { return this.borderColor; }
            set
            {
                if (this.borderColor == value)
                    return;

                this.borderColor = value;
            }
        }

        private Color backColor = Color.White;
        /// <summary>
        /// 背景颜色
        /// </summary>
        [Description("背景颜色")]
        [PropertyOrder(-198)]
        [DefaultValue(typeof(Color), "White")]
        public Color BackColor
        {
            get { return this.backColor; }
            set
            {
                if (this.backColor == value)
                    return;

                this.backColor = value;
            }
        }

        private Color shadowColor = Color.DarkGray;
        /// <summary>
        /// 四周阴影颜色
        /// </summary>
        [Description("四周阴影颜色")]
        [PropertyOrder(-196)]
        [DefaultValue(typeof(Color), "DarkGray")]
        public Color ShadowColor
        {
            get { return this.shadowColor; }
            set
            {
                if (this.shadowColor == value)
                    return;

                this.shadowColor = value;
            }
        }

        private int maxHeight = 0;
        /// <summary>
        /// 下拉框最大高度（0为自动计算）
        /// </summary>
        [Description("下拉框最大高度（0为自动计算）")]
        [PropertyOrder(-192)]
        [DefaultValue(0)]
        public int MaxHeight
        {
            get { return this.maxHeight; }
            set
            {
                if (this.maxHeight == value || value <= 0)
                    return;

                this.maxHeight = value;
            }
        }

        private string nullItemsTipText = "没有可以选择选项";
        /// <summary>
        /// 空数据源提示文本
        /// </summary>
        [Description("空数据源提示文本")]
        [PropertyOrder(-186)]
        [DefaultValue("没有可以选择选项")]
        public string NullItemsTipText
        {
            get { return this.nullItemsTipText; }
            set
            {
                if (this.nullItemsTipText == value)
                    return;

                this.nullItemsTipText = value;
            }
        }

        private Color nullItemsTipBackColor = Color.White;
        /// <summary>
        /// 空数据源提示背景颜色
        /// </summary>
        [Description("空数据源提示背景颜色")]
        [PropertyOrder(-185)]
        [DefaultValue(typeof(Color), "White")]
        public Color NullItemsTipBackColor
        {
            get { return this.nullItemsTipBackColor; }
            set
            {
                if (this.nullItemsTipBackColor == value)
                    return;

                this.nullItemsTipBackColor = value;
            }
        }

        private Color nullItemsTipTextColor = Color.Tomato;
        /// <summary>
        /// 空数据源提示文本颜色
        /// </summary>
        [Description("空数据源提示文本颜色")]
        [PropertyOrder(-184)]
        [DefaultValue(typeof(Color), "Tomato")]
        public Color NullItemsTipTextColor
        {
            get { return this.nullItemsTipTextColor; }
            set
            {
                if (this.nullItemsTipTextColor == value)
                    return;

                this.nullItemsTipTextColor = value;
            }
        }

        private bool locateVisible = false;
        /// <summary>
        /// 已选中选项是否显示定位
        /// </summary>
        [Description("已选中选项是否显示定位")]
        [PropertyOrder(-183)]
        [DefaultValue(false)]
        public bool LocateVisible
        {
            get { return this.locateVisible; }
            set
            {
                if (this.locateVisible == value)
                    return;

                this.locateVisible = value;
            }
        }

        private Color locateColor = Color.Gold;
        /// <summary>
        /// 已选中选项定位颜色
        /// </summary>
        [Description("已选中选项定位颜色")]
        [PropertyOrder(-182)]
        [DefaultValue(typeof(Color), "Gold")]
        public Color LocateColor
        {
            get { return this.locateColor; }
            set
            {
                if (this.locateColor == value)
                    return;

                this.locateColor = value;
            }
        }

        #region 选项

        private int itemHeight = 30;
        /// <summary>
        /// 选项高度
        /// </summary>
        [Description("选项高度")]
        [PropertyOrder(-181)]
        [DefaultValue(30)]
        public int ItemHeight
        {
            get { return this.itemHeight; }
            set
            {
                if (this.itemHeight == value || value < 0)
                    return;

                this.itemHeight = value;
            }
        }

        private LRPadding lRPadding = new LRPadding(4, 4);
        /// <summary>
        /// 左右内边距
        /// </summary>
        [Description("左右内边距")]
        [Category("杂项")]
        [PropertyOrder(-180)]
        [DefaultValue(typeof(LRPadding), "4, 4")]
        public LRPadding LRPadding
        {
            get { return this.lRPadding; }
            set
            {
                if (value.Left < 0)
                    value.Left = 0;
                if (value.Right < 0)
                    value.Right = 0;
                if (this.lRPadding == value)
                    return;

                this.lRPadding = value;
            }
        }

        private Color itemSplitterColor = Color.FromArgb(224, 224, 224);
        /// <summary>
        /// 选项分隔线颜色
        /// </summary>
        [Description(" 选项分隔线颜色")]
        [PropertyOrder(-178)]
        [DefaultValue(typeof(Color), "224, 224, 224")]
        public Color ItemSplitterColor
        {
            get { return this.itemSplitterColor; }
            set
            {
                if (this.itemSplitterColor == value)
                    return;

                this.itemSplitterColor = value;
            }
        }

        private Color itemBackNormalColor = Color.White;
        /// <summary>
        /// 选项背景颜色（正常）
        /// </summary>
        [Description(" 选项背景颜色（正常）")]
        [PropertyOrder(-176)]
        [DefaultValue(typeof(Color), "White")]
        public Color ItemBackNormalColor
        {
            get { return this.itemBackNormalColor; }
            set
            {
                if (this.itemBackNormalColor == value)
                    return;

                this.itemBackNormalColor = value;
            }
        }

        private Color itemTextNormalColor = Color.Gray;
        /// <summary>
        /// 选项文本颜色（正常）
        /// </summary>
        [Description(" 选项文本颜色（正常）")]
        [PropertyOrder(-174)]
        [DefaultValue(typeof(Color), "Gray")]
        public Color ItemTextNormalColor
        {
            get { return this.itemTextNormalColor; }
            set
            {
                if (this.itemTextNormalColor == value)
                    return;

                this.itemTextNormalColor = value;
            }
        }

        private Color itemBackEnterColor = Color.FromArgb(60, 153, 204, 204);
        /// <summary>
        /// 选项背景颜色（鼠标进入）
        /// </summary>
        [Description(" 选项背景颜色（鼠标进入）")]
        [PropertyOrder(-172)]
        [DefaultValue(typeof(Color), "60, 153, 204, 204")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color ItemBackEnterColor
        {
            get { return this.itemBackEnterColor; }
            set
            {
                if (this.itemBackEnterColor == value)
                    return;

                this.itemBackEnterColor = value;
            }
        }

        private Color itemTextEnterColor = Color.Gray;
        /// <summary>
        /// 选项文本颜色（鼠标进入）
        /// </summary>
        [Description(" 选项文本颜色（鼠标进入）")]
        [PropertyOrder(-170)]
        [DefaultValue(typeof(Color), "Gray")]
        public Color ItemTextEnterColor
        {
            get { return this.itemTextEnterColor; }
            set
            {
                if (this.itemTextEnterColor == value)
                    return;

                this.itemTextEnterColor = value;
            }
        }

        private Color itemBackSelectedColor = Color.FromArgb(153, 204, 204);
        /// <summary>
        /// 选项背景颜色（选中）
        /// </summary>
        [Description(" 选项背景颜色（选中）")]
        [PropertyOrder(-168)]
        [DefaultValue(typeof(Color), "153, 204, 204")]
        public Color ItemBackSelectedColor
        {
            get { return this.itemBackSelectedColor; }
            set
            {
                if (this.itemBackSelectedColor == value)
                    return;

                this.itemBackSelectedColor = value;
            }
        }

        private Color itemTextSelectedColor = Color.White;
        /// <summary>
        /// 选项文本颜色（选中）
        /// </summary>
        [Description(" 选项文本颜色（选中）")]
        [PropertyOrder(-166)]
        [DefaultValue(typeof(Color), "White")]
        public Color ItemTextSelectedColor
        {
            get { return this.itemTextSelectedColor; }
            set
            {
                if (this.itemTextSelectedColor == value)
                    return;

                this.itemTextSelectedColor = value;
            }
        }

        private Color itemBackDisableColor = Color.FromArgb(234, 234, 234);
        /// <summary>
        /// 选项背景颜色（禁止）
        /// </summary>
        [Description(" 选项背景颜色（禁止）")]
        [PropertyOrder(-164)]
        [DefaultValue(typeof(Color), "234, 234, 234")]
        public Color ItemBackDisableColor
        {
            get { return this.itemBackDisableColor; }
            set
            {
                if (this.itemBackDisableColor == value)
                    return;

                this.itemBackDisableColor = value;
            }
        }

        private Color itemTextDisableColor = Color.Silver;
        /// <summary>
        /// 选项文本颜色（禁止）
        /// </summary>
        [Description("选项文本颜色（禁止）")]
        [PropertyOrder(-162)]
        [DefaultValue(typeof(Color), "Silver")]
        public Color ItemTextDisableColor
        {
            get { return this.itemTextDisableColor; }
            set
            {
                if (this.itemTextDisableColor == value)
                    return;

                this.itemTextDisableColor = value;
            }
        }

        private bool itemImageVisible = false;
        /// <summary>
        /// 是否显示选项图片
        /// </summary>
        [Description("是否显示选项图片")]
        [PropertyOrder(-160)]
        [DefaultValue(false)]
        public bool ItemImageVisible
        {
            get { return this.itemImageVisible; }
            set
            {
                if (this.itemImageVisible == value)
                    return;

                this.itemImageVisible = value;
                this.InitializeInvalidate();
            }
        }

        private Size itemImageSize = new Size(18, 18);
        /// <summary>
        /// 选项图片Size
        /// </summary>
        [Description("选项图片Size")]
        [PropertyOrder(-158)]
        [DefaultValue(typeof(Size), "18,18")]
        public Size ItemImageSize
        {
            get { return this.itemImageSize; }
            set
            {
                if (value.Width <= 0)
                    value.Width = 0;
                if (value.Height <= 0)
                    value.Height = 0;
                if (this.itemImageSize == value)
                    return;

                this.itemImageSize = value;
            }
        }

        private LRMargin itemImageLRMargin = new LRMargin(4, 4);
        /// <summary>
        /// 选项图片左右外边距
        /// </summary>
        [Description("选项图片左右外边距")]
        [PropertyOrder(-157)]
        [DefaultValue(typeof(LRMargin), "4, 4")]
        public LRMargin ItemImageLRMargin
        {
            get { return this.itemImageLRMargin; }
            set
            {
                if (value.Left < 0)
                    value.Left = 0;
                if (value.Right < 0)
                    value.Right = 0;
                if (this.itemImageLRMargin == value)
                    return;

                this.itemImageLRMargin = value;
            }
        }

        private Image itemImage = null;
        /// <summary>
        /// 选项图片
        /// </summary>
        [Description("选项图片")]
        [PropertyOrder(-156)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.Repaint)]
        public Image ItemImage
        {
            get { return this.itemImage; }
            set
            {
                if (this.itemImage == value)
                    return;

                this.itemImage = value;
            }
        }

        #endregion

        #region 滚动条

        private int scrollThickness = 12;
        /// <summary>
        /// 滑条厚度
        /// </summary>
        [Description("滑条厚度")]
        [PropertyOrder(-140)]
        [DefaultValue(12)]
        public int ScrollThickness
        {
            get { return this.scrollThickness; }
            set
            {
                if (this.scrollThickness == value || value < 0)
                    return;

                this.scrollThickness = value;
            }
        }

        private int scrollSlideMinHeight = 26;
        /// <summary>
        /// 滑块最小高度
        /// </summary>
        [Description("滑块最小高度")]
        [PropertyOrder(-138)]
        [DefaultValue(26)]
        public int ScrollSlideMinHeight
        {
            get { return this.scrollSlideMinHeight; }
            set
            {
                if (this.scrollSlideMinHeight == value || value < 1)
                    return;

                this.scrollSlideMinHeight = value;
            }
        }

        private Color scrollBarColor = Color.FromArgb(60, 0, 0, 0);
        /// <summary>
        /// 滑条颜色
        /// </summary>
        [Description("滑条颜色")]
        [PropertyOrder(-136)]
        [DefaultValue(typeof(Color), "60, 0, 0, 0")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color ScrollBarColor
        {
            get { return this.scrollBarColor; }
            set
            {
                if (this.scrollBarColor == value)
                    return;

                this.scrollBarColor = value;
            }
        }

        private Color scrollSlideColor = Color.FromArgb(90, 0, 0, 0);
        /// <summary>
        /// 滑块颜色
        /// </summary>
        [Description("滑块颜色")]
        [PropertyOrder(-134)]
        [DefaultValue(typeof(Color), "90, 0, 0, 0")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color ScrollSlideColor
        {
            get { return this.scrollSlideColor; }
            set
            {
                if (this.scrollSlideColor == value)
                    return;

                this.scrollSlideColor = value;
            }
        }

        #endregion

        #endregion

        #region 字段

        private DropDownListPlus owner = null;

        #endregion

        public DropDownListPlusListItemsStyle(DropDownListPlus owner)
        {
            this.owner = owner;
        }

        #region 私有方法

        /// <summary>
        /// 刷新控件
        /// </summary>
        public void Invalidate()
        {
            if (this.owner != null)
            {
                this.owner.Invalidate();
            }
        }

        /// <summary>
        /// 重新计算控件刷新控件
        /// </summary>
        public void InitializeInvalidate()
        {
            if (this.owner != null)
            {
                this.owner.InitializeRectangle();
                this.owner.Invalidate();
            }
        }

        #endregion

    }

}
